package com.njupt.StringProblem;

import java.util.Scanner;

/**
 * 卡玛网替换数字
 */
public class ReplaceNumbers {

    /**
     * StringBuider可以变字符串，使用插入删除API
     * @param string
     * @return
     */
    public String replaceNumbers(String string){
        StringBuilder sb = new StringBuilder(string);
        for (int i = 0; i < sb.length(); i++) {
            if(sb.charAt(i) >= '0' && sb.charAt(i) <= '9'){
                sb.deleteCharAt(i);
                sb.insert(i,"number");
                i += 5;
            }
        }
        return sb.toString();
    }

    /**
     * 双指针法，从后向前遍历，采用扩容数组的方式
     * 从后向前填充元素，避免了从前往后填充元素时，每次添加元素都要将元素向后移动的问题
     * @param string
     * @return
     */
    public static String replaceNumbers1(String string){
        int count = 0;
        for (int i = 0; i < string.length(); i++) {
            if(Character.isDigit(string.charAt(i))){
                count++;
            }
        }
        char[] newS = new char[string.length() + count*5];
        for (int i = 0; i < string.length(); i++) {
            newS[i] = string.charAt(i);
        }
        int oldIndex = string.length()-1;
        int newIndex = newS.length-1;

        while(oldIndex>=0){

            if(newS[oldIndex]>='0' && newS[oldIndex]<= '9'){
                newS[newIndex--] = 'r';
                newS[newIndex--] = 'e';
                newS[newIndex--] = 'b';
                newS[newIndex--] = 'm';
                newS[newIndex--] = 'u';
                newS[newIndex--] = 'n';
                oldIndex--;
            }else {
                newS[newIndex--] = newS[oldIndex--];
            }
        }
        return new String(newS);
    }

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String s1 = sc.nextLine();
        ReplaceNumbers test = new ReplaceNumbers();
        System.out.println(test.replaceNumbers1(s1));
        sc.close();
    }
}
